function applyMixins(derivedCtor:any,baseCtors:any){
    // 遍历基础属性
    baseCtors.forEach(baseCtor => {
        // 进行赋值操作
            Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
                derivedCtor.prototype[name] = baseCtor.prototype[name]
            })
    });
}


class Disposable {
    isDisposed:boolean;
    dispose(){
        this.isDisposed = true
    }
}

class Activatable {
    isActive:boolean;
    activate(){
        this.isActive = true
    }
    deactivate(){
        this.isActive = false
    }
}
// 没使用extends而是使用implements。 把类当成了接口，
// 仅使用Disposable和Activatable的类型而非其实现。
class SmartObject implements Disposable,Activatable {
    // Disposable 的占位属性 将来会通过 mixin 把真正的函数和方法 赋值 给这两个占位属性
    isDisposed:boolean = false;
    dispose:()=> void;

    // Activatable 
    isActive:boolean = false;
    activate:() => void;
    deactivate:() => void;

    constructor(){
        setInterval(()=> console.log(this.isActive + ":"+this.isDisposed),500)
    }
    interact(){
        this.activate()
    }
}

applyMixins(SmartObject,[Disposable,Activatable])
// 编译为 js 以后也太容易看懂了把
let smartObj = new SmartObject();
setTimeout(()=>smartObj.interact(),1000)
